package com.yz.newspaper.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yz.newspaper.pojo.po.Grade;
import com.yz.newspaper.pojo.po.PublishColumn;
import com.yz.newspaper.pojo.result.Result;
import com.yz.newspaper.service.IGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 等级表 前端控制器
 *
 * @author author
 * @since 2024-04-21
 */
@RestController
@RequestMapping("/grade")
public class GradeController {

    @Autowired
    private IGradeService gradeService;

    @GetMapping("/all")
    public Result<List<Grade>> getAll(){
        List<Grade> list = gradeService.list();
        return Result.success(list);
    }

    @GetMapping("/byMedia")
    public Result<List<Grade>> getHitsByMedia(String media) {
        if (media == null) {
            return  Result.error("请输入媒体");
        }
        List<Grade> list = gradeService.list(new LambdaQueryWrapper<Grade>()
                .eq(Grade::getMedia, media));
        if (list.isEmpty()) {
            return Result.error("当前媒体没有等级分类");
        }
        return Result.success(list);
    }
}
